<template>
  <view class="container">
    <view class="unansower" v-for="(item, index) in list" :key="item.id">
      <view style="display: flex; justify-content: space-between; align-items: center">
        <view class="top">
          <text style="font-weight: bold; font-size: 28rpx; color: #333333">{{ item.subject_name }}作业</text>
          <text style="font-weight: 500; font-size: 24rpx; color: #333333; padding-left: 20rpx">来自{{ item.teacher_name }}</text>
        </view>
        <view class="time">{{ '(' + item.week + ')' + item.statrTime }} 布置</view>
      </view>
      <view class="endtime">
        <text v-if="item.status == 1">提交截至：{{ '(' + item.endtime_week + ')' + item.endTime }}</text>
        <text v-else>已提交</text>
      </view>
      <view class="title">{{ item.content }}</view>
      <view class="line"></view>
      <view style="display: flex; justify-content: flex-end">
        <view class="btn" v-if="item.status == 1" @click="goansower(item)">去回答</view>
        <view class="checkbtn" v-else @click="gocheckhomework(item.id)">查看作业详情</view>
      </view>
    </view>
  </view>
</template>

<script>
import dayjs from 'dayjs';
export default {
  data() {
    return {
      status: 0,
      list: []
    };
  },
  methods: {
    // 获取作业列表
    async getlist() {
      const res = await uni.$http.post('/homework/indexUser');
      console.log('获取作业列表', res);
      this.list = res.data.data.list;
      this.list.forEach((item) => {
        item.statrTime = dayjs(item.arrange * 1000).format('YYYY/MM/DD hh:mm');
        item.endTime = dayjs(item.endtime * 1000).format('YYYY/MM/DD hh:mm');
      });
      if (this.list.length == 0) {
        uni.showToast({
          title: '暂无数据',
          icon: 'none'
        });
      }
    },
    goansower(data) {
      uni.navigateTo({
        url: '/parents/myhomework/myhomework?data=' + JSON.stringify(data)
      });
    },
    gocheckhomework(id) {
      uni.navigateTo({
        url: '/parents/homeworkdetail/homeworkdetail?id=' + id
      });
    }
  },
  onLoad() {},
  onShow() {
    // 获取作业的列表
    this.getlist();
  }
};
</script>

<style lang="scss" scoped>
.container {
  box-sizing: border-box;
  padding: 30rpx;
  .unansower {
    box-sizing: border-box;
    width: 690rpx;
    height: 328rpx;
    background: #f5f7ff;
    padding: 30rpx;
    border-radius: 20rpx 20rpx 20rpx 20rpx;
    margin-bottom: 20rpx;
    .top {
    }
    .time {
      font-family: PingFang SC, PingFang SC;
      font-weight: 500;
      font-size: 24rpx;
      color: #333333;
    }
    .endtime {
      font-weight: 500;
      font-size: 28rpx;
      color: #333333;
      margin-top: 20rpx;
      margin-bottom: 30rpx;
    }
    .title {
      font-family: PingFang SC, PingFang SC;
      font-weight: bold;
      font-size: 28rpx;
      color: #333333;
      padding-bottom: 30rpx;
    }
    .line {
      width: 630rpx;
      height: 0;
      border: 2rpx solid #e3e3e3;
    }
    .btn {
      box-sizing: border-box;
      width: 160rpx;
      height: 60rpx;
      background: #3553e8;
      color: #fff;
      text-align: center;
      line-height: 60rpx;
      margin-top: 20rpx;
      border-radius: 100rpx 100rpx 100rpx 100rpx;
    }
    .checkbtn {
      box-sizing: border-box;
      width: 246rpx;
      height: 60rpx;
      text-align: center;
      line-height: 60rpx;
      color: #fff;
      background: #3553e8;
      margin-top: 20rpx;
      border-radius: 100rpx 100rpx 100rpx 100rpx;
    }
  }
}
</style>
